//
//  main.m
//  NSNumber
//
//  Created by mir_yan on 2018/10/1.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSNumber * num = [NSNumber numberWithChar:'a'];
        NSLog(@"%@", num);
        
        NSNumber * num1 = @22;
        NSLog(@"%@", num1);
        NSLog(@"%d", [num1 intValue]);
        
        int a = 32;
        NSNumber * num2 = @(a);
        NSLog(@"%@", num2);
        
        NSArray * arr = @[num, num1];
        NSLog(@"%@", arr);
        
//        NSValue
        
        typedef struct {
            int age;
            char * name;
            char sex;
        } SPerson;
        
        SPerson person;
        person.name = "zhangsan";
        person.age = 22;
        person.sex = 'm';
        
        // 将一个建构体转换NSValue对象
        NSValue* value = [NSValue valueWithBytes:&person objCType:@encode(SPerson)];
        NSLog(@"%s", @encode(SPerson));
        
        SPerson person2;
        // 将一个NSValue对象转换建构体
        [value getValue:&person2];
        
        NSLog(@"%s", person2.name);
        NSLog(@"%d", person2.age);
        NSLog(@"%c", person2.sex);
        
        NSRange range = {12, 2};
        // 常用结构体
        NSValue * raa = [NSValue valueWithRange:range];
        // 拆箱
        NSLog(@"%@", NSStringFromRange([raa rangeValue]));
        
    }
    return 0;
}
